package com.wzh.service;

import com.wzh.dao.MesDao;
import com.wzh.pojo.Po.Mes;
import com.wzh.pojo.Po.User;
import com.wzh.pojo.Req.DataReq;
import com.wzh.pojo.Resp.DataResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MesService {
	@Autowired
	private MesDao mesDao;

	public DataResp<Object> add(Mes mes) {
		DataResp<Object> resp=new DataResp<>();
        DataReq dataReq =new DataReq();
        dataReq.setOrderId(mes.getOrderId());
		List<Mes> list= mesDao.find(dataReq);
		if (!list.isEmpty()){
			resp.setMes("你已经提交过该订单了哦!请耐心等待");
			resp.setCode(203);
			return resp;
		}


		Integer code =mesDao.add(mes);
		if (code>0){
			resp.setMes("发送成功！");
		}else{
			resp.setMes("发送失败！");
		}
		return  resp;
	}

	public DataResp<Object> show(DataReq req) {
		DataResp<Object> resp=new DataResp<>();
		List<Mes> list= mesDao.find(req);
		if (list.size()!=0){
			resp.setData(list);
			resp.setMes("查询成功！");
		}else{
			resp.setMes("查询失败！");
		}
		return  resp;
	}

	public DataResp<Object> update(Mes mes) {
		DataResp<Object> resp=new DataResp<>();
		DataReq req=new DataReq();
		req.setOrderId(mes.getOrderId());
		List<Mes> list= mesDao.find(req);
		if (list.size()!=0){

			Integer res =mesDao.update(mes);
//			resp.setData(list);
//			resp.setMes("查询成功！");
		}else{
			resp.setMes("未查询到该订单号！请先获取验证码,提交订单");
		}
		return  resp;
	}
}
